<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>芯佑电商_会员登录</title>
    <#include "/website/commonWebsite.html">
    <!--==选择框==-->
    <link href="/website/js/checkbox/checkbox.css" rel="stylesheet" type="text/css" />
    <script src="/website/js/jq-cookie.js"></script>
    <script src="/website/js/aes.min.js"></script>
    <!--==本页面白色背景==-->
    <style>
        html{ background: #fff; }
    </style>
</head>
<body>
<!--==页面==-->
<div class="login">
    <!--==头部==-->
    <div class="login-top">
        <h1><a href="#"><img src="images/login.png" alt=""></a></h1>
        <ul>
            <li><a href="/website/home">商城首页</a></li>
            <!--<li><a href="#">查找商品</a></li>-->
            <li><a href="/website/register">会员注册</a></li>
        </ul>
    </div>
    <!--==内容==-->
    <div class="login-content">
        <div class="login-content-le"><img src="images/login_02.png" alt=""></div>
        <div class="login-content-ri">
            <h1>会员登录</h1>
            <h2>Member login</h2>
            <!--输入框-->
            <div class="login-content-ris">
                <dl>
                    <dt>手机号</dt>
                    <dd><input type="text" id="username" placeholder="请输入用户名"></dd>
                </dl>
            </div>
            <!--输入框-->
            <div class="login-content-ris">
                <dl>
                    <dt>密码</dt>
                    <dd><input type="password" id="password"  placeholder="请输入您的密码"></dd>
                </dl>
            </div>
            <!--按钮-->
            <div class="login-content-rin"><button type="button" onclick="login()">确认登录</button></div>
            <!--记住登录-->
            <div class="checklist">
                <label><input id="rememberLogin" type="checkbox" onclick="rememberLogin(this);"><span></span>记住登录</label>
                <p><a href="/website/register">会员注册</a></p>
            </div>
        </div>
    </div>
    <!--== 版权 ==-->
    <div class="login-copyright">
        <span>
            <a href="#">关于我们</a>
            <strong>|</strong>
            <a href="#">免责声明</a>
            <strong>|</strong>
            <a href="#">联系我们</a>
            <strong>|</strong>
            <a href="#">商务合作</a>
            <strong>|</strong>
            <a href="#">售后保障</a>
        </span>
        <p>Copyright © 2019 芯佑电商  沪ICP备1008888号</p>
    </div>
</div>
</body>
<script>
    //js加密
    function encrypt(word) {
        var key = CryptoJS.enc.Utf8.parse("IDontKonwWhoYouA");
        var srcs = CryptoJS.enc.Utf8.parse(word);
        var encrypted = CryptoJS.AES.encrypt(srcs, key, {
            mode : CryptoJS.mode.ECB,
            padding : CryptoJS.pad.Pkcs7
        });
        return encrypted.toString();
    }
    //js解密
    function decrypt(word) {
        var key = CryptoJS.enc.Utf8.parse("IDontKonwWhoYouA");
        var decrypt = CryptoJS.AES.decrypt(word, key, {
            mode : CryptoJS.mode.ECB,
            padding : CryptoJS.pad.Pkcs7
        });
        return CryptoJS.enc.Utf8.stringify(decrypt).toString();
    }
    $(function(){
        var cookieUsername = $.cookie("REMEMBER_LOGIN_USERNAME");
        var cookiePassword = $.cookie("REMEMBER_LOGIN_PASSWORD");
        if(cookieUsername!=undefined&&cookieUsername!=null&&cookieUsername!=''&&cookiePassword!=undefined&&cookiePassword!=null&&cookiePassword!=''){
            var username = decrypt(cookieUsername);
            var password = decrypt(cookiePassword);
            console.log(username)
            console.log(password);
        }
        if(username!=null&&username!=''&&username!=undefined&&password!=null&&password!=''&&password!=undefined){
            $("#rememberLogin").parent().addClass("checkbox_color_c");
            $("#rememberLogin").attr("checked","checked");
            $("#username").val(username);
            $("#password").val(password);
        }
    })
//登录方法
function login() {
    var checkbox_color_c = $("#rememberLogin").parent().attr("class");
    var rememberStatus = null;
    if(checkbox_color_c=="checkbox_color_c"){
        rememberStatus="1";
    }
    var hh = $("#username").val();
    var tt = $("#password").val();
    $.ajax({
        url: '/user/login',
        type: 'post',
        data: {
            phone: hh,
            password: tt,
            rememberStatus: rememberStatus
        },
        dataType: 'json',
        success: function (resp) {
            if (resp.code=="200") {
                window.location.href = "/website/home";
            } else {
                //$("#errorMsg").text(resp.message);
                layer.msg(resp.message);
            }
        },
        error: function () {
           layer.msg("异常错误...");
        }
    });
}

//复选框
function rememberLogin(obj) {
    var username = $("#username").val();
    var password = $("#password").val();
    var checkbox_color_c =$(obj).parent().attr("class");
    if (checkbox_color_c=="checkbox_color_c"){
        $(obj).parent().removeClass("checkbox_color_c");
        $(".sholis-cheb").find("label").removeClass("checkbox_color_c");
        $(".sholis-cheb").find("input").removeAttr("checked","checked");
        //清楚cookie里面的username和password
        $.cookie('REMEMBER_LOGIN_USERNAME', "",{ expires: 1, path: '/' });
        $.cookie('REMEMBER_LOGIN_PASSWORD', "",{ expires: 1, path: '/' });
    }else{
        $(obj).parent().addClass("checkbox_color_c");
        var show = $(".sholis-li").find(".sholis-che");
        var checkbox_color_c=$(".sholis-li").find(".checkbox_color_c");
        if(show.length==checkbox_color_c.length){
            $(".sholis-cheb").find("label").addClass("checkbox_color_c");
            $(".sholis-cheb").find("input").attr("checked","checked");
        }
    };
};
</script>
</html>